/*
 * Created by JFormDesigner on Sun Oct 17 17:02:00 CST 2021
 */

package view.info;

import library.controller.FrameListener;
import library.po.User;
import library.service.UserService;
import library.service.impl.UserServiceImpl;
import view.main.MainFrame;

import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;

/**
 * @author unknown
 */
public class PersonalInfoDialog extends JDialog {
    public PersonalInfoDialog(MainFrame owner, User user) {
        super(owner);
        this.listener = owner.getMainListener();
        this.owner = owner;
        this.user = userService.selectById(user.getUserId());
        initComponents();
        this.setVisible(true);
        this.validate();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - unknown
        dialogPane = new JPanel();
        contentPanel = new JPanel();
        name = new JLabel();
        id = new JLabel();
        sex = new JLabel();
        type = new JLabel();
        credit = new JLabel();
        books = new JLabel();
        idValue = new JLabel();
        booksButton = new JButton();
        okButton = new JButton();
        sexValue = new JLabel();
        nameValue = new JLabel();
        typeValue = new JLabel();
        creditValue = new JLabel();
        //======== this ========
        setTitle("查看个人信息");
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== dialogPane ========
        {
            dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
            dialogPane.setBorder (new CompoundBorder( new TitledBorder (new
                    EmptyBorder( 0, 0, 0, 0) , "", TitledBorder. CENTER, TitledBorder. BOTTOM, new Font ("Dia\u006cog" , Font .BOLD ,12 ),
                    Color. red) ,dialogPane. getBorder( )) ); dialogPane. addPropertyChangeListener (new java. beans. PropertyChangeListener( )
        { @Override public void propertyChange (java .beans .PropertyChangeEvent e) {if ("bord\u0065r" .equals (e .getPropertyName () ))
            throw new RuntimeException( ); }} );
            dialogPane.setLayout(null);

            //======== contentPanel ========
            {
                contentPanel.setLayout(null);

                //---- name ----
                name.setText("姓名：");
                name.setFont(name.getFont().deriveFont(name.getFont().getSize() + 10f));
                contentPanel.add(name);
                name.setBounds(95, 150, 70, 35);

                //---- id ----
                id.setText("用户名：");
                id.setFont(id.getFont().deriveFont(id.getFont().getSize() + 10f));
                contentPanel.add(id);
                id.setBounds(new Rectangle(new Point(95, 45), id.getPreferredSize()));

                //---- sex ----
                sex.setText("性别：");
                sex.setFont(sex.getFont().deriveFont(sex.getFont().getSize() + 10f));
                contentPanel.add(sex);
                sex.setBounds(new Rectangle(new Point(400, 45), sex.getPreferredSize()));

                //---- type ----
                type.setText("身份：");
                type.setFont(type.getFont().deriveFont(type.getFont().getSize() + 10f));
                contentPanel.add(type);
                type.setBounds(new Rectangle(new Point(400, 155), type.getPreferredSize()));

                //---- credit ----
                credit.setText("信用分：");
                credit.setFont(credit.getFont().deriveFont(credit.getFont().getSize() + 10f));
                contentPanel.add(credit);
                credit.setBounds(new Rectangle(new Point(95, 255), credit.getPreferredSize()));

                //---- books ----
                books.setText("已借图书：");
                books.setFont(books.getFont().deriveFont(books.getFont().getSize() + 10f));
                contentPanel.add(books);
                books.setBounds(new Rectangle(new Point(400, 255), books.getPreferredSize()));

                //---- idValue ----
                idValue.setText(user.getUserId());
                idValue.setFont(idValue.getFont().deriveFont(idValue.getFont().getSize() + 10f));
                contentPanel.add(idValue);
                idValue.setBounds(new Rectangle(new Point(195, 45), idValue.getPreferredSize()));

                //---- booksButton ----
                booksButton.addActionListener(listener);
                booksButton.setActionCommand("ViewBorrowBooks");
                booksButton.setText("\u70b9\u6b64\u67e5\u770b");
                contentPanel.add(booksButton);
                booksButton.setBounds(515, 255, 85, 30);

                //---- okButton ----
                okButton.setText("OK");
                okButton.addActionListener(listener);
                okButton.setActionCommand("InfoExit");
                okButton.setFont(okButton.getFont().deriveFont(Font.BOLD, okButton.getFont().getSize() + 12f));
                contentPanel.add(okButton);
                okButton.setBounds(355, 370, 110, 60);

                //---- sexValue ----
                sexValue.setText(user.getUserSex());
                sexValue.setFont(sexValue.getFont().deriveFont(sexValue.getFont().getSize() + 10f));
                contentPanel.add(sexValue);
                sexValue.setBounds(new Rectangle(new Point(480, 45), sexValue.getPreferredSize()));

                //---- nameValue ----
                nameValue.setText(user.getUserName());
                nameValue.setFont(nameValue.getFont().deriveFont(nameValue.getFont().getSize() + 10f));
                contentPanel.add(nameValue);
                nameValue.setBounds(165, 150, 70, 35);

                //---- typeValue ----
                typeValue.setText(listener.typeToIdentity(user.getUserType()));
                typeValue.setFont(typeValue.getFont().deriveFont(typeValue.getFont().getSize() + 10f));
                contentPanel.add(typeValue);
                typeValue.setBounds(new Rectangle(new Point(480, 155), typeValue.getPreferredSize()));

                //---- creditValue ----
                creditValue.setText(user.getUserCredit().toString());
                creditValue.setFont(creditValue.getFont().deriveFont(creditValue.getFont().getSize() + 10f));
                contentPanel.add(creditValue);
                creditValue.setBounds(new Rectangle(new Point(185, 255), creditValue.getPreferredSize()));

                {
                    // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < contentPanel.getComponentCount(); i++) {
                        Rectangle bounds = contentPanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = contentPanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    contentPanel.setMinimumSize(preferredSize);
                    contentPanel.setPreferredSize(preferredSize);
                }
            }
            dialogPane.add(contentPanel);
            contentPanel.setBounds(12, 12, 799, 449);

            {
                // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < dialogPane.getComponentCount(); i++) {
                    Rectangle bounds = dialogPane.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = dialogPane.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                dialogPane.setMinimumSize(preferredSize);
                dialogPane.setPreferredSize(preferredSize);
            }
        }
        contentPane.add(dialogPane, BorderLayout.CENTER);
        setSize(825, 505);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }
    public FrameListener getListener(){
        return this.listener;
    }
    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - unknown
    private JPanel dialogPane;
    private JPanel contentPanel;
    private JLabel name;
    private JLabel id;
    private JLabel sex;
    private JLabel type;
    private JLabel credit;
    private JLabel books;
    private JLabel idValue;
    private JButton booksButton;
    private JButton okButton;
    private JLabel sexValue;
    private JLabel nameValue;
    private JLabel typeValue;
    private JLabel creditValue;
    private User user;
    private FrameListener listener;
    private MainFrame owner;
    private UserService userService = new UserServiceImpl();
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}